// 对api进行检索
const fs = require("fs");
const ds = require("./api.json");
const cj = require("./ydJson/common.json")

let luaCj = "";
cj.forEach(e => {
    let def = ds.find(d => d.nameUS == e);
    if(def){
        //参数提取
        let params = []
        let pc=""
        let args = ""
        def.args.split(",").forEach(p=>{
            let t = p.trim().split(" ");
            params.push({
                type:t[0],
                name:t[1]
            });
            //生成参数 
     });
        params.forEach(p=>{
            pc += `
---@param ${p.name} ${p.type}`
            args += `${p.name}, `;
        })
        luaCj +=`
${def.description ? '---'+def.description+'\n' : ''}${def.title ? '---'+def.title+'\n' : ''}${def.comment ? '---'+def.comment+'\n' : ''}${pc}
---@return ${def.returns}
cj.${def.nameUS} = function(${args.substr(0,args.length-2)})end
`
    }
});
fs.writeFileSync("../lua/api.lua",luaCj);
console.log("ok")